var tabPanelItems = new Array();

Ext.onReady(function() {

	new Ext.tab.Panel({
		renderTo : Ext.getBody(),
		layout : 'fit',
		height : '100%',
		width : '100%',
		border : false,
		tabPosition : "top", 
		itemId :'reportQueryTabPanel',
		plain: true,   
		
		items : initReportQueryTablPanel(tables_id) 
	});

	
});

/**
 * 初始化套表
 * 
 * @param tables_id
 * @param q_condition
 * @param closeHidden
 * @returns
 */
 function initReportQueryTablPanel(tables_id) {
	loadTabInfo(tables_id);
	
	return tabPanelItems;
}

/**
 * 加载配置信息
 * 
 * @param code
 * @param q_condition
 */
 function loadTabInfo(tables_id) {
	Ext.Ajax.request({
		method : 'POST',
		url : "/sys-report/getReportQueryTabInfo",
		params : {
			tables_id : tables_id
		},
		async : false,
		success : function(response, options) {
			// 获取返回的JSON，并根据gridid，获取表头配置信息
			var respText = Ext.util.JSON.decode(response.responseText);
			var tabList = respText.tabList;
			tabPanelConf(tabList);
		},
		failure : function(response, options) {
			Ext.MessageBox.minWidth = 120;
			Ext.Msg.alert('提示', '获取报表配置信息失败！');
		}
	});
}

/**
 * 页签配置
 * 
 * @param tablesList
 */
 function tabPanelConf(tabList){
	var urlParam = getUrlParam();
	for ( var i = 0; i < tabList.length; i++) {
		var tabUrl = '/report/page/plat/query/reportQuery.html?code=' + tabList[i].Q_ID + urlParam;
		tabPanelItems.push({
			title: '<span title="'+tabList[i].TAB_NAME+'">'+tabList[i].TAB_NAME+'</span>',
			closable: false,
			layout: 'fit',
			xtype:"panel",
			itemId:'tabpable'+tabList[i].Q_ID,
			html:'<iframe id="tablesCover" src="'+tabUrl+'" '
				 +'style="width:100%;height:100%;margin:0px auto;" frameborder="0"></iframe>'
	   });
		
	}
}



/**
 * 拼接url中的参数
 */
 function getUrlParam() {
	var url = location.search; //获取url中"?"符后的字串
	var urlParam = "";
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		var strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			var paramKey = strs[i].split("=")[0];
			var paramValue = stripXss(unescape(strs[i].split("=")[1]));
			if(paramKey != "code"){
				urlParam = "&" + paramKey + "=" + paramValue;
			}
		}
	}
	return urlParam;
}

